package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private  SetmealService SetmealService;


    /**
     * 获取所有套餐信息
     * @return
     */
    @PostMapping("/getSetmeal")
    public Result getSetmeal(){
        log.info("获取所有套餐信息：{}");
        List<Setmeal> setmealList = SetmealService.list();
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmealList);
    }

    /**
     * 根据id查询套餐详情
     * @param id
     * @return
     */
    @PostMapping("/findById")
    public Result findById(Integer id){
        log.info("根据id查询套餐详情：{}",id);
        Setmeal setmealById = SetmealService.findById(id);
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmealById);
    }
}
